﻿// <copyright>
// Copyright (c) 2008 - 2009, Microsoft, All Rights Reserved
// </copyright>
//
// Licensed under the Microsoft Public License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at 
//
// http://www.opensource.org/licenses/ms-pl.html

namespace LiveLabs.Logging
{
    using System;
    using LiveLabs.Logging.Resources;

    /// <summary>
    /// Enumeration of levels that can be logged to
    /// </summary>
    public enum LogLevel
    {
        /// <summary>
        /// The Fatal Level
        /// </summary>
        /// <remarks>
        /// This level should be used when an unexpected error occurs that cannot be 
        /// recovered from, requires immediate human intervention, and the application
        /// will most likely shutdown.
        /// </remarks>
        Fatal,

        /// <summary>
        /// The Error Level 
        /// </summary>
        /// <remarks>
        /// This level should be used when an unexpected error occurs that cannot be
        /// recovered from and likely requires human intervention.  But the application
        /// may not shutdown if the error is transitive (i.e. database down).
        /// </remarks>
        Error,

        /// <summary>
        /// The Warning Level 
        /// </summary>
        /// <remarks>
        /// This level should be used when an unexpected error occurs that can
        /// be recovered from and a human should look at the issue at their earliest
        /// possible convenience.
        /// </remarks>
        Warn,

        /// <summary>
        /// The Inform Level 
        /// </summary>
        /// <remarks>
        /// This level should be used for reporting normal running information to the end user.
        /// This can include order ids being processed, RSS urls being parsed, etc.
        /// </remarks>
        Inform,

        /// <summary>
        /// The Debug Level 
        /// </summary>
        /// <remarks>
        /// This level should be used for basic, high level debugging statements.  Such as,
        /// entering and leaving a method, direction taking in conditional statements, 
        /// events sent or received, and important objects.
        /// </remarks>
        Debug,

        /// <summary>
        /// The Verbose Level
        /// </summary>
        /// <remarks>
        /// This level should be used for debugging that generates large amounts of output.
        /// Such as, mouse events, state of a loop (i.e. current index), method parameters,
        /// etc.
        /// </remarks>
        Verbose
    }

    /// <summary>
    /// Simple utilities for working with <see cref="LogLevel"/> enumeration.
    /// </summary>
    internal static class LogLevelUtils
    {
        internal static bool IsValid(this LogLevel @this)
        {
            return @this >= LogLevel.Fatal && @this <= LogLevel.Verbose;
        }

        internal static LogLevel Valid(this LogLevel @this, string name)
        {
            if (!@this.IsValid())
            {
#if SILVERLIGHT
                throw new ArgumentOutOfRangeException(name, Messages.LogLevelOutOfRange);
#else
                throw new ArgumentOutOfRangeException(name, @this, Messages.LogLevelOutOfRange);
#endif
            }

            return @this;
        }
    }
}
